<template>
  <div class="init_main">
    <p class="name_sty">{{ name }}</p>
    <div class="query">
      *科室：
      <el-select
        v-model="query.sectionId"
        filterable
        placeholder=""
        clearable
        size="mini"
      >
        <el-option
          :label="item.Name"
          :value="item.Id"
          v-for="item in SectionsList"
          :key="item.Id"
        >
        </el-option>
      </el-select>
      *起始日期：
      <el-date-picker
        size="mini"
        v-model="query.dateStart"
        format="yyyy 年 MM 月 dd 日"
        value-format="yyyy-MM-dd"
        type="date"
        placeholder="选择日期"
      >
      </el-date-picker>
      *结束日期：
      <el-date-picker
        size="mini"
        v-model="query.dateEnd"
        format="yyyy 年 MM 月 dd 日"
        value-format="yyyy-MM-dd"
        type="date"
        placeholder="选择日期"
      >
      </el-date-picker>

      <!-- 姓名：
      <el-input
        size="mini"
        style="width: 150px"
        v-model="query.userName"
      ></el-input> -->
      *排班：
      <el-select
        v-model="query.categoryName"
        placeholder=""
        clearable
        size="mini"
      >
        <el-option
          :label="item.Name"
          :value="item.Name"
          v-for="item in pbList"
          :key="item.Id"
        >
        </el-option>
      </el-select>
      <el-button
        plain
        size="mini"
        icon="el-icon-search"
        style="margin-left: 10px"
        @click="getList"
        >查询</el-button
      >
      <!-- <el-button
        plain
        size="mini"
        icon="el-icon-plus"
        type="primary"
        @click="open_dialog('新增')"
        >新增</el-button
      >
      <el-button
        plain
        size="mini"
        icon="el-icon-edit"
        type="primary"
        @click="open_dialog('修改')"
        >修改</el-button
      >
      <el-button
        plain
        size="mini"
        icon="el-icon-delete"
        type="danger"
        @click="del_row"
        >删除</el-button
      > -->
    </div>
    <div class="table">
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        height="600"
        highlight-current-row
        @current-change="row_click"
      >
        <!-- <el-table-column prop="Type" label="类型" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.Type | to_type }}</span>
          </template>
        </el-table-column> -->
        <el-table-column prop="UserName" label="姓名" align="center">
        </el-table-column>
        <el-table-column prop="Count" label="班次" align="center">
        </el-table-column>
      </el-table>
    </div>
    <!-- <div class="page">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange_page"
        :current-page="query.CurrentPage"
        :page-sizes="[10, 15, 50, 100]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="query.total"
      >
      </el-pagination>
    </div> -->
    <!-- 弹层 -->
    <el-dialog
      :title="dialog_title"
      :visible.sync="dialogVisible"
      width="45%"
      :before-close="handleClose"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <table border="1" style="width: 100%" v-if="dialogVisible">
        <tr>
          <td class="tac">类型：</td>
          <td>
            <el-select
              v-model="form.Type"
              style="width: 100%"
              placeholder=""
              size="mini"
            >
              <el-option label="白班" value="1"> </el-option>
              <el-option label="夜班" value="2"> </el-option>
              <el-option label="请假" value="3"> </el-option>
              <el-option label="休息" value="4"> </el-option>
              <el-option label="公休假" value="5"> </el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td class="tac">备注：</td>
          <td><el-input size="mini" v-model="form.Name"></el-input></td>
        </tr>
        <tr>
          <td class="tac">颜色：</td>
          <td><el-color-picker v-model="form.Color"></el-color-picker></td>
        </tr>
        <tr>
          <td class="tac">时长：</td>
          <td><el-input size="mini" v-model="form.timeDuration"></el-input></td>
        </tr>
      </table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose" size="mini">关 闭</el-button>
        <el-button type="primary" @click="btn_ok" size="mini">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      query: {
        type: "",
        name: "",
      },
      tableData: [],
      dialogVisible: false,
      dialog_title: "",
      row_info: null,
      form: {
        Type: "",
        Title: "",
        Content: "",
        Image: "",
      },
      userList: [],
      SectionsList: [],
      pbList: [],
    };
  },
  mounted() {
    this.name = this.$route.meta.title;
    this.getSections();
    this.getPB();
  },
  filters: {
    to_type(val) {
      var str = "";
      if (val == 1) {
        str = "白班";
      }
      if (val == 2) {
        str = "夜班";
      }
      if (val == 3) {
        str = "请假";
      }
      if (val == 4) {
        str = "休息";
      }
      if (val == 5) {
        str = "公休假";
      }
      return str;
    },
  },
  methods: {
    getSections() {
      this.$get("/Schedule/Sections").then((res) => {
        this.SectionsList = res.Data;
      });
    },
    getPB() {
      var body = { type: "", name: "" };
      this.$post("/ScheduleCategory/GetAll", body).then((res) => {
        this.pbList = res.Data;
      });
    },
    getList() {
      this.$post("/Schedule/Statistic", this.query).then((res) => {
        this.tableData = res.Data;
      });
    },
    getUserList() {
      this.$post("/Bs/GetAllUserList").then((res) => {
        this.userList = res.Data;
      });
    },
    open_windo(url) {
      window.open(url);
    },
    row_click(row) {
      if (!row) {
        this.row_info = null;
        return;
      }
      var srt = JSON.stringify(row);
      this.row_info = JSON.parse(srt);
    },
    del_row() {
      this.$get("/ScheduleCategory/SoftDelete/" + this.row_info.Id).then(
        (res) => {
          this.getList();
        }
      );
    },
    handleClose() {
      this.form = { Users: [] };
      this.dialogVisible = false;
    },
    btn_ok() {
      // this.form
      var url = this.form.Id
        ? "/ScheduleCategory/Update"
        : "/ScheduleCategory/Create";
      if (this.form.Id) {
        this.$put(url, this.form).then((res) => {
          this.getList();
          this.handleClose();
        });
      } else {
        this.$post(url, this.form).then((res) => {
          this.getList();
          this.handleClose();
        });
      }
    },
    open_dialog(val) {
      this.dialog_title = val + "质控人员";
      if (val == "新增") {
        this.dialogVisible = true;
        return;
      }
      if (val == "修改" && this.row_info) {
        this.form = this.row_info;
        this.dialogVisible = true;
        return;
        // this.$get("/Option/GetOneNew/" + this.row_info.Id).then((res) => {
        //   this.form = res.Data;
        //   this.dialogVisible = true;
        //   return;
        // });
      } else {
        this.$notify.error({
          title: "错误",
          message: "请选择一条数据后操作！",
        });
        return;
      }
    },
    handleSizeChange(val) {
      this.query.pageSize = val;
      this.query.CurrentPage = 1;
    },
    handleCurrentChange_page(val) {
      this.query.CurrentPage = val;
      this.getList();
    },
    setUserName(id) {
      console.log(id);
    },
  },
};
</script>

<style scoped lang='scss'>
.init_main {
  background-color: #fff;
  height: calc(100vh - 60px);
  border: 1px solid #333;
  border-radius: 5px;
  margin: 5px;
  padding: 10px;
  font-family: "FangSong";
  color: #000;
  .name_sty {
    color: #000;
    font-weight: 700;
    font-size: 18px;
    font-family: "FangSong";
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
  }
  .table {
    margin-top: 15px;
  }
  .page {
    text-align: right;
  }
}
::v-deep .el-table__body tr.current-row > td.el-table__cell {
  background-color: rgb(208, 229, 250);
  color: rgb(65, 158, 255);
  font-weight: 700;
}
.tac {
  text-align: center;
}
.color_box {
  display: inline-block;
  width: 20px;
  height: 15px;
  border: 1px solid #000;
}
</style>